package com.cloud.tsp.controller;

import com.cloud.api.constants.StrVo;
import com.cloud.api.domain.forward.ResponseData;
import com.cloud.api.domain.job.QueryService;
import com.cloud.api.domain.service.ServiceStatistics;
import com.cloud.api.domain.service.StationAuth;
import com.cloud.api.domain.service.StationInfo;
import com.cloud.api.domain.service.StationServiceBaseInfo;
import com.cloud.core.util.R;
import com.cloud.log.annotation.Log;
import com.cloud.log.enums.BusinessType;
import com.cloud.log.enums.OperatorType;
import com.cloud.mybatis.domain.TableDataInfo;
import com.cloud.tsp.service.IStationServiceBaseInfoService;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.time.LocalDate;
import java.time.LocalDateTime;

/**
 * <p>
 * 服务站授权信息表 前端控制器
 * </p>
 *
 * @author haohaibo
 * @since 2025-03-12
 */
@Tag(name = "服务站管理模块")
@ApiSupport(order = 202)
@RestController
@RequestMapping("/station-service-base-info")
public class StationServiceBaseInfoController {

    @Resource
    private IStationServiceBaseInfoService stationServiceBaseInfoService;

    @Tag(name = "v1.0")
    @Operation(summary = "查询维修站列表（管理）")
    @PostMapping("/getServiceStationList")
    @Log(title = "维修站信息-查询维修站列表", businessType = BusinessType.OTHER, operatorType = OperatorType.MANAGE)
    public TableDataInfo<StationServiceBaseInfo> selectServiceStationList(@RequestBody @Valid QueryService para){
        return stationServiceBaseInfoService.selectServiceStationList(para);
    }

    @Tag(name = "v1.0")
    @Operation(summary = "新增或修改维修站（管理）")
    @PostMapping("/InsertOrUpdateStationInfo")
    @Log(title = "维修站信息-新增或修改维修站", businessType = BusinessType.OTHER, operatorType = OperatorType.MANAGE)
    public R<String> InsertOrUpdateStationInfo(@RequestBody @Valid StationInfo para){
        return R.ok(stationServiceBaseInfoService.InsertOrUpdateStationInfo(para));
    }

    @Tag(name = "v1.0")
    @Operation(summary = "新增或修改授权信息（管理）")
    @PostMapping("/InsertOrUpdateStationAuth")
    @Log(title = "维修站信息-新增或修改授权信息", businessType = BusinessType.OTHER, operatorType = OperatorType.MANAGE)
    public R<String> InsertOrUpdateStationAuth(@RequestBody @Valid StationAuth para){
        return R.ok(stationServiceBaseInfoService.InsertOrUpdateStationAuth(para));
    }

    @Tag(name = "v1.0")
    @Operation(summary = "查询维修站详情（管理）")
    @PostMapping("/getServiceStationDetail")
    @Log(title = "维修站信息-查询维修站详情", businessType = BusinessType.OTHER, operatorType = OperatorType.MANAGE)
    public R<StationServiceBaseInfo> selectServiceStationDetail(@RequestBody @Valid StrVo para){
        return R.ok(stationServiceBaseInfoService.getById(para.getId()));
    }

    @Tag(name = "v1.0")
    @Operation(summary = "批量修改授权信息（管理）")
    @PostMapping("/updateServiceStationAuth")
    @Log(title = "维修站信息-批量修改授权信息", businessType = BusinessType.UPDATE, operatorType = OperatorType.MANAGE)
    public R<ResponseData> updateServiceStationAuth(@RequestParam MultipartFile file, @RequestParam("authorizationStart") LocalDate authorizationStart, @RequestParam("authorizationEnd") LocalDate authorizationEnd) throws IOException {
        String key = "service";
        return R.ok(stationServiceBaseInfoService.updateServiceStationAuth(file,authorizationStart,authorizationEnd,key));
    }

    @Tag(name = "v1.0")
    @Operation(summary = "页面统计信息（管理）")
    @PostMapping("/getServiceStationStatistics")
    @Log(title = "维修站信息-页面统计信息", businessType = BusinessType.OTHER, operatorType = OperatorType.MANAGE)
    public R<ServiceStatistics> getServiceStationStatistics(){
        return R.ok(stationServiceBaseInfoService.getServiceStationStatistics());
    }

    @Tag(name = "v1.0")
    @Operation(summary = "下载模板（管理）")
    @PostMapping("/downloadTemplate")
    @Log(title = "维修站信息-下载模板", businessType = BusinessType.EXPORT, operatorType = OperatorType.MANAGE)
    public void downloadTemplate(HttpServletResponse response) throws IOException{
        stationServiceBaseInfoService.downloadTemplate(response);
    }

    @Tag(name = "v1.0")
    @Operation(summary = "导出数据（管理）")
    @PostMapping("/exportData")
    @Log(title = "维修站信息-导出数据", businessType = BusinessType.EXPORT, operatorType = OperatorType.MANAGE)
    public void exportData(HttpServletResponse response, QueryService para) throws IOException{
        stationServiceBaseInfoService.exportData(response,para);
    }
}
